/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vastcm.stuhealth.client;

import com.vastcm.stuhealth.client.entity.School;
import com.vastcm.stuhealth.client.entity.SchoolTreeNode;
import com.vastcm.stuhealth.client.entity.UploadLog;
import com.vastcm.stuhealth.client.entity.service.ISchoolService;
import com.vastcm.stuhealth.client.entity.service.ISchoolTreeNodeService;
import com.vastcm.stuhealth.client.entity.service.IUploadLogService;
import com.vastcm.stuhealth.client.framework.SystemUtils;
import com.vastcm.stuhealth.client.framework.ui.KernelUI;
import com.vastcm.stuhealth.client.framework.ui.UI;
import com.vastcm.stuhealth.client.framework.ui.UIContext;
import com.vastcm.stuhealth.client.framework.ui.UICreationException;
import com.vastcm.stuhealth.client.framework.ui.UIFactory;
import com.vastcm.stuhealth.client.framework.ui.UIType;
import com.vastcm.stuhealth.client.io.IAuthFileImporter;
import com.vastcm.stuhealth.client.ui.TreeUtils;
import com.vastcm.stuhealth.client.utils.ExceptionUtils;

import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.plaf.FileChooserUI;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.JButton;

/**
 *
 * @author House
 */
public class SchoolTreePanel extends KernelUI {
    
    private Logger logger = LoggerFactory.getLogger(SchoolTreePanel.class);
    
    private ISchoolTreeNodeService schoolTreeNodeService;
    private List<SchoolTreeListener> schoolTreeListeners = new ArrayList<SchoolTreeListener>();


    public void addSchoolTreeListener(SchoolTreeListener schoolTreeListener) {
        schoolTreeListeners.add(schoolTreeListener);
    }
    
    // a queue to record which nodes is updated and need to be store to database.
    private Queue<DefaultMutableTreeNode> dirtyTreeNodes = new ArrayDeque<DefaultMutableTreeNode>();

    /**
     * Creates new form SchoolTreePanel
     */
    public SchoolTreePanel() {
        initComponents();
        initTree();
    }
    
    private ISchoolTreeNodeService getService() {
        if(schoolTreeNodeService == null) {
            schoolTreeNodeService = AppContext.getBean("schoolTreeNodeService", ISchoolTreeNodeService.class);
        }
        return schoolTreeNodeService;
    }
    
    private void initTree() {
        List<SchoolTreeNode> nodes = getService().getNormalNodes();
        for(int i = 0; i < nodes.size(); i++) {
            logger.debug("node[" + i + "]: " + nodes.get(i).getLongNumber());
        }
        rebuildTree(getService().getNormalNodes(), false);
    }
    
    
    public void setToolbarVisible(boolean visible) {
        jToolBar.setVisible(visible);
    }
    
    protected void addTreeListener() {
        jTree1.addTreeSelectionListener(new TreeSelectionListener() {

            public void valueChanged(TreeSelectionEvent e) {
                treeNodeSelectChanged(e);
            }
        });
        
    }

    protected void treeNodeSelectChanged(TreeSelectionEvent e) {
        TreePath path = jTree1.getSelectionPath();
        if(path == null) {
            btnSchoolEdit.setEnabled(false);
            return;
         }
         DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
         SchoolTreeNode schoolTreeNode = (SchoolTreeNode) node.getUserObject();
         if(SchoolTreeNode.TYPE_SCHOOL == schoolTreeNode.getType()) {
            btnSchoolEdit.setEnabled(true);
            btnRemoveSchool.setEnabled(true);
            logger.debug("btnSchoolEdit.setEnabled(true)");
         }
         else {
            btnSchoolEdit.setEnabled(false);
            btnRemoveSchool.setEnabled(false);
            logger.debug("btnSchoolEdit.setEnabled(false)");
         }              
         for(SchoolTreeListener lsnr : schoolTreeListeners) {
             lsnr.nodeSelectChanged(schoolTreeNode);
         }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar = new javax.swing.JToolBar();
        btnImportAuthFile = new javax.swing.JButton();
        btnSchoolEdit = new javax.swing.JButton();
        chkDisplayMergedSchool = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();

        setLayout(new java.awt.BorderLayout());

        jToolBar.setFloatable(false);
        jToolBar.setRollover(true);

        btnImportAuthFile.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/book_add.png"))); // NOI18N
        btnImportAuthFile.setText("导入验证文件");
        btnImportAuthFile.setFocusable(false);
        btnImportAuthFile.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnImportAuthFile.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnImportAuthFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImportAuthFileActionPerformed(evt);
            }
        });
        jToolBar.add(btnImportAuthFile);

        btnSchoolEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/house.png"))); // NOI18N
        btnSchoolEdit.setText("学校信息维护");
        btnSchoolEdit.setFocusable(false);
        btnSchoolEdit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSchoolEdit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSchoolEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSchoolEditActionPerformed(evt);
            }
        });
        jToolBar.add(btnSchoolEdit);

        chkDisplayMergedSchool.setText("显示被合并学校");
        chkDisplayMergedSchool.setFocusable(false);
        chkDisplayMergedSchool.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        chkDisplayMergedSchool.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        chkDisplayMergedSchool.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                chkDisplayMergedSchoolItemStateChanged(evt);
            }
        });
        
        btnRemoveSchool = new JButton("删除学校信息");
        btnRemoveSchool.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/application_delete.png"))); 
        btnRemoveSchool.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnRemoveSchool.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnRemoveSchool.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSchoolRemoveActionPerformed(evt);
            }
        });
        jToolBar.add(btnRemoveSchool);
        jToolBar.add(chkDisplayMergedSchool);

        add(jToolBar, java.awt.BorderLayout.NORTH);

        jScrollPane1.setViewportView(jTree1);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    public Queue<DefaultMutableTreeNode> getDirtyTreeNodes() {
        return dirtyTreeNodes;
    }
    
    public void saveTree() {
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) jTree1.getModel().getRoot();
        Iterator<DefaultMutableTreeNode> iterTree = dirtyTreeNodes.iterator();
        List<SchoolTreeNode> schoolTreeNodeLs = new ArrayList<SchoolTreeNode>();
        while (iterTree.hasNext()) {
            DefaultMutableTreeNode node = iterTree.next();
            if(node.isRoot()) {
                continue;
            }
            logger.debug("schoolTree: " + node.getUserObject().getClass().getName() + "=" + node.getUserObject());
            schoolTreeNodeLs.add( (SchoolTreeNode)node.getUserObject() );
        }
        getService().save(schoolTreeNodeLs);
        chkDisplayMergedSchool.setSelected(false);
        rebuildTree(getService().getNormalNodes(), false);
    }
    
    public void refreshTree() {
    	rebuildTree(getService().getNormalNodes(), false);
    }
    
    private void rebuildTree(List<SchoolTreeNode> treeNodes, boolean isDirty) {
        jTree1.removeAll();
        dirtyTreeNodes.clear();
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("学校");
        DefaultTreeModel treeModel = new DefaultTreeModel(root);
        jTree1.setModel(treeModel);
        Map<String, DefaultMutableTreeNode> nodeMap = new HashMap<String, DefaultMutableTreeNode>();
        nodeMap.put("root", root);
        for(SchoolTreeNode t : treeNodes) {
            logger.debug("node: " + t.getLongNumber());
            DefaultMutableTreeNode n = new DefaultMutableTreeNode(t);
            DefaultMutableTreeNode parent = null;
            if(t.getLongNumber().indexOf("!") == -1) {
                parent = nodeMap.get("root");
            }
            else {
                parent = nodeMap.get(t.getLongNumber().substring(0, t.getLongNumber().lastIndexOf("!")));
            }   
            parent.add(n); 
            nodeMap.put(t.getLongNumber(), n);
            if(isDirty) {
                dirtyTreeNodes.add(n);                
            }
        }
        addTreeListener();
        TreeUtils.expand(jTree1, new TreePath(root), 5);
        jTree1.setRootVisible(false);
    }
    
    public JTree getTree() {
        return jTree1;
    }
    
    private void btnImportAuthFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportAuthFileActionPerformed
        TreeModel treeModel = jTree1.getModel();
//        int childCount = treeModel.getChildCount(treeModel.getRoot());
//        logger.debug("Has tree node? " + childCount);
//        if(childCount > 0) {
//            int confirm = JOptionPane.showConfirmDialog(this, "已存在学校信息，是否清除原有数据？请谨慎选择！", "请确认", JOptionPane.YES_NO_OPTION);
//            if(JOptionPane.YES_OPTION != confirm) {
//                return;    
//            }
//        }
        IAuthFileImporter afi = AppContext.getBean("authFileImporter", IAuthFileImporter.class);
        String appHome = System.getProperty("appHome");
        JFileChooser fc = new JFileChooser(appHome);
        fc.showOpenDialog(SwingUtilities.getWindowAncestor(this));
        File f = fc.getSelectedFile();
        if(f == null) {
        	return;
        }
        logger.info("File " + f + " is selected.");
//        getService().removeAll();
        try {
            List<School> schools = afi.parse(f);
            ISchoolService schoolSrv = AppContext.getBean("schoolService", ISchoolService.class);
            ISchoolTreeNodeService schoolTreeNodeSrv = AppContext.getBean("schoolTreeNodeService", ISchoolTreeNodeService.class);
//            schoolSrv.removeAll();
            for(School s : schools) { // 一个或多个学校，有且只有一个是新增的，其他都是被合并的学校
            	if(School.STATUS_NORMAL.equals(s.getStatus())) {
            		String schoolCode = s.getSchoolCode();
            		if(schoolSrv.getByCode(schoolCode) != null) {
                    	int confirm = JOptionPane.showConfirmDialog(null, "编码为 [" + schoolCode + "] 的学校已经存在，是否删除并重新导入？", "提示", JOptionPane.YES_NO_OPTION);
                    	if(JOptionPane.YES_OPTION == confirm) {
                    		schoolSrv.removeByCode(schoolCode);
                    		schoolTreeNodeSrv.removeByCode(schoolCode);
                    	}
                    	else {
                    		return;
                    	}
                    }
            		
            		SchoolTreeNode node = new SchoolTreeNode();
            		node.setCode(s.getSchoolCode());
            		node.setLongNumber(s.getCityId() + "!" + s.getDistrictCode() + "!" + s.getSchoolCode());
            		node.setName(s.getName());
            		node.setParentCode(s.getDistrictCode());
            		node.setStatus(s.getStatus());
            		node.setType(SchoolTreeNode.TYPE_SCHOOL);
            		node.setLevel(3);
            		schoolSrv.save(s);
                    schoolTreeNodeSrv.save(node);
                    
                    SchoolTreeNode nodeCity = new SchoolTreeNode();
                    nodeCity.setCode(s.getCityId());
                    nodeCity.setLevel(1);
                    nodeCity.setLongNumber(s.getCityId());
                    nodeCity.setName(s.getCityName());
                    nodeCity.setParentCode(null);
                    nodeCity.setStatus(SchoolTreeNode.STATUS_NORMAL);
                    nodeCity.setType(SchoolTreeNode.TYPE_CITY);
                    schoolTreeNodeSrv.saveIfNotExistsByCode(nodeCity);
                    
                    SchoolTreeNode nodeDistrict = new SchoolTreeNode();
                    nodeDistrict.setCode(s.getDistrictCode());
                    nodeDistrict.setLevel(2);
                    nodeDistrict.setLongNumber(s.getCityId() + "!" + s.getDistrictCode());
                    nodeDistrict.setName(s.getDistrictName());
                    nodeDistrict.setParentCode(s.getCityId());
                    nodeDistrict.setStatus(SchoolTreeNode.STATUS_NORMAL);
                    nodeDistrict.setType(SchoolTreeNode.TYPE_DISTRICT);
                    schoolTreeNodeSrv.saveIfNotExistsByCode(nodeDistrict);
            	}
            	else {
            		schoolSrv.updateStatus(s.getSchoolCode(), s.getStatus(), s.getHostSchoolCode());
            		schoolTreeNodeSrv.updateStatus(s.getSchoolCode(), s.getStatus());
            	}
            }
            
            
            List<SchoolTreeNode> schoolTreeNodes = schoolTreeNodeSrv.getNormalNodes();
            rebuildTree(schoolTreeNodes, false);
//            saveTree();
            chkDisplayMergedSchool.setSelected(false);
        } 
        catch (IOException ex) {
            ExceptionUtils.writeExceptionLog(logger, ex);
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
        
    }//GEN-LAST:event_btnImportAuthFileActionPerformed

    protected List<SchoolTreeNode> transform2SchoolTreeNode(List<School> schoolLs) {
        List<SchoolTreeNode> rs = new ArrayList<SchoolTreeNode>();
        Map<String, SchoolTreeNode> map = new TreeMap<String, SchoolTreeNode>(); // key: longNumber
        for(School school : schoolLs) {
            String cityId = school.getCityId();
            if(map.get(cityId) == null) {
                SchoolTreeNode treeNode = new SchoolTreeNode();
                treeNode.setCode(cityId);
                treeNode.setLevel(1);
                treeNode.setLongNumber(cityId);
                treeNode.setName(school.getCityName());
                treeNode.setStatus(SchoolTreeNode.STATUS_NORMAL);
                treeNode.setType(SchoolTreeNode.TYPE_CITY);
                map.put(treeNode.getLongNumber(), treeNode);
            }
            String districtId = school.getDistrictCode();
            if(map.get(cityId + "!" + districtId) == null) {
                SchoolTreeNode treeNode = new SchoolTreeNode();
                treeNode.setCode(districtId);
                treeNode.setLevel(2);
                treeNode.setLongNumber(cityId + "!" + districtId);
                treeNode.setName(school.getDistrictName());
                treeNode.setStatus(SchoolTreeNode.STATUS_NORMAL);
                treeNode.setType(SchoolTreeNode.TYPE_DISTRICT);
                map.put(treeNode.getLongNumber(), treeNode);
            }
            String schoolId = school.getSchoolCode();
            String longNo = cityId + "!" + districtId + "!" + schoolId;
            if(map.get(longNo) == null) {
                SchoolTreeNode treeNode = new SchoolTreeNode();
                treeNode.setCode(schoolId);
                treeNode.setLevel(3);
                treeNode.setLongNumber(longNo);
                treeNode.setName(school.getName());
                treeNode.setStatus(school.getStatus());
                treeNode.setType(SchoolTreeNode.TYPE_SCHOOL);
                map.put(treeNode.getLongNumber(), treeNode);
            }
        }
        Iterator<SchoolTreeNode> iter = map.values().iterator();
        while(iter.hasNext()) {
            rs.add(iter.next());
        }
        return rs;
    }
    
    private void btnSchoolRemoveActionPerformed(ActionEvent evt) {
    	TreePath path = jTree1.getSelectionPath();
        if(path == null) {
            JOptionPane.showMessageDialog(this, "请先选择学校！");
            return;
        }
    	int confirm = JOptionPane.showConfirmDialog(this, "删除学校信息将删除此学校中的所有班级，确认要删除吗？", "删除确认", JOptionPane.YES_NO_OPTION);
    	if(JOptionPane.YES_OPTION == confirm) {
    		DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            SchoolTreeNode schoolTreeNode = (SchoolTreeNode) node.getUserObject();
            
    		ISchoolTreeNodeService schoolTreeSrv = AppContext.getBean("schoolTreeNodeService", ISchoolTreeNodeService.class);
    		schoolTreeSrv.removeRecursive(schoolTreeNode.getLongNumber());
    		logger.info("School node [" + schoolTreeNode.getLongNumber() + "] and its children nodes were removed recursively.");
    		
    		ISchoolService schoolSrv = AppContext.getBean("schoolService", ISchoolService.class);
    		schoolSrv.removeByCode(schoolTreeNode.getCode());
    		logger.info("School [" + schoolTreeNode.getCode() + " " + schoolTreeNode.getName() + "] was removed.");
    		
    		refreshTree();
    		
    		JOptionPane.showMessageDialog(this, "删除成功！");
    	}
    }
    
    private void btnSchoolEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSchoolEditActionPerformed
        TreePath path = jTree1.getSelectionPath();
        if(path == null) {
            JOptionPane.showMessageDialog(this, "请先选择学校！");
            return;
        }
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        logger.debug("node clicked: " + node.getUserObject());
        SchoolTreeNode schoolTreeNode = (SchoolTreeNode) node.getUserObject();
        if(!SchoolTreeNode.STATUS_NORMAL.equals(schoolTreeNode.getStatus())) {
            JOptionPane.showMessageDialog(this, "不能维护 被合并或撤销的学校！");
            return;
        }
        try {
            UIContext uiCtx = new UIContext();
            uiCtx.set(UIContext.UI_TITLE, "学校信息维护");
            uiCtx.set("owner", this);
            uiCtx.set("schoolCode", schoolTreeNode.getCode());
            uiCtx.set("schoolTreeNode", node);
            uiCtx.set("tree", jTree1);
            UI<SchoolPanel> ui = UIFactory.create(SchoolPanel.class, UIType.MODAL, uiCtx, null);
            ui.setVisible(true);
        } 
        catch (Exception ex) {
            ExceptionUtils.writeExceptionLog(logger, ex);
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnSchoolEditActionPerformed

    private void chkDisplayMergedSchoolItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkDisplayMergedSchoolItemStateChanged
        if(ItemEvent.SELECTED == evt.getStateChange()) {
            setMergedSchoolVisible(true);
        }
        else {
            setMergedSchoolVisible(false);
        }
    }//GEN-LAST:event_chkDisplayMergedSchoolItemStateChanged

    public void setMergedSchoolVisible(boolean visible) {
        List schools = null;
        if(visible) {
            schools = getService().getAllNodes();
        }
        else {
            schools = getService().getNormalNodes();
        }
        rebuildTree(schools, false);
    }
    
    public void setIsDisplayClass(boolean isDisplayClass) {
        if(!isDisplayClass) {
            List<DefaultMutableTreeNode> node2Remove = new ArrayList<DefaultMutableTreeNode>();
            DefaultTreeModel model = (DefaultTreeModel) jTree1.getModel();
            DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
            Enumeration<DefaultMutableTreeNode> nodes = root.depthFirstEnumeration();
            while (nodes.hasMoreElements()) {
                DefaultMutableTreeNode node = nodes.nextElement();
                if(node == root) {
                    continue;
                }
                SchoolTreeNode schNode = (SchoolTreeNode) node.getUserObject();
                logger.info(schNode.getName() + "=" + schNode.getType());
                if(SchoolTreeNode.TYPE_CLASS == schNode.getType()) {
                    node2Remove.add(node);
                }
            }
            for(DefaultMutableTreeNode n : node2Remove) {
                model.removeNodeFromParent(n);
            }
        }
    }
    
    public void displayUploadMsg() {
    	String year = String.valueOf(GlobalVariables.getGlobalVariables().getYear());
    	String term = String.valueOf(GlobalVariables.getGlobalVariables().getTerm());
    	IUploadLogService uploadLogSrv = AppContext.getBean("uploadLogService", IUploadLogService.class);
    	List<UploadLog> uploadLogLs = uploadLogSrv.getLogs(year, term);
    	Map<String, UploadLog> logMap = new HashMap<String, UploadLog>(); // key=schoolCode
    	for(UploadLog l : uploadLogLs) {
    		logMap.put(l.getSchoolCode(), l);
    	}
         DefaultTreeModel model = (DefaultTreeModel) jTree1.getModel();
         DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
         Enumeration<DefaultMutableTreeNode> nodes = root.depthFirstEnumeration();
         while (nodes.hasMoreElements()) {
             DefaultMutableTreeNode node = nodes.nextElement();
             if(node == root) {
                 continue;
             }
             SchoolTreeNode schNode = (SchoolTreeNode) node.getUserObject();
             logger.info(schNode.getName() + "=" + schNode.getType());
             if(SchoolTreeNode.TYPE_SCHOOL == schNode.getType()) {
            	 if(logMap.containsKey(schNode.getCode())) {
            		 schNode.setName(schNode.getName() + " - (数据已上传) ");
                     node.setUserObject(schNode);
            	 }
             }
         }
         jTree1.updateUI();
    }
    
    public void displaySecCodeMsg() {
    	ISchoolService schSrv = AppContext.getBean("schoolService", ISchoolService.class);
    	List<School> schs = schSrv.getAll();
        Set<String> schsWithSecCode = new HashSet<String>();
        for(School s : schs) {
        	if(s.getSecCode() != null && !s.getSecCode().trim().isEmpty()) {
        		schsWithSecCode.add(s.getSchoolCode());
        	}
        }
        DefaultTreeModel model = (DefaultTreeModel) jTree1.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        Enumeration<DefaultMutableTreeNode> nodes = root.depthFirstEnumeration();
        while (nodes.hasMoreElements()) {
            DefaultMutableTreeNode node = nodes.nextElement();
            if(node == root) {
                continue;
            }
            SchoolTreeNode schNode = (SchoolTreeNode) node.getUserObject();
            logger.info(schNode.getName() + "=" + schNode.getType());
            if(SchoolTreeNode.TYPE_SCHOOL == schNode.getType()) {
           	 if(!schsWithSecCode.contains(schNode.getCode())) {
           		 schNode.setName(schNode.getName() + " - [验证文件已过期，请重新导入！] ");
                    node.setUserObject(schNode);
           	 }
            }
        }
        jTree1.updateUI();
    }
    
    @Override
    public Object getValue() {
    	if(jTree1.getLastSelectedPathComponent()==null)
    		return null;
        return ((DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent()).getUserObject();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JButton btnImportAuthFile;
    protected javax.swing.JButton btnSchoolEdit;
    protected javax.swing.JCheckBox chkDisplayMergedSchool;
    private javax.swing.JScrollPane jScrollPane1;
    protected javax.swing.JToolBar jToolBar;
    protected javax.swing.JTree jTree1;
    protected JButton btnRemoveSchool;
    // End of variables declaration//GEN-END:variables
}
